package community.hospital.common;


import lombok.Data;

import java.util.HashMap;

import static community.hospital.common.Constant.ERROR;
import static community.hospital.common.Constant.SUCCESS;

/**
 * @author ydj
 */
@Data
public class R<T> {
    private Integer code;
    private String message;
    private T result;
    private HashMap<String,Object> map = new HashMap<>();

    private R(){

    }

    private R(Integer code,String msg,T data){
        this.code = code;
        this.message = msg;
        this.result = data;
    }

    public static <T> R<T> ok(String msg,T data){
      return new R<T>(SUCCESS,msg,data);
    }

    public static <T> R<T> ok(String msg){
        return R.ok(msg, null);
    }
    public static <T> R<T> ok(T data){
        return R.ok("success", data);
    }

    public static <T> R<T> error(String msg){
        return new R<>(ERROR,msg,null);
    }

    public R<T> put(String key,Object value) {
        map.put(key,value);
        return this;
    }






}
